package com.cy.pj.sys.web.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.common.pojo.Pager;
import com.cy.pj.common.util.PageUtil;
import com.cy.pj.sys.pojo.SysRole;
import com.cy.pj.sys.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
@Api(tags = "角色")
public class SysRoleController {
    //@Autowired
    private SysRoleService sysRoleService;
    public SysRoleController(){}
    @Autowired
    public void setSysRoleService(SysRoleService sysRoleService) {
        this.sysRoleService = sysRoleService;
    }

    //http://localhost/role/checkRoles
    @ApiOperation(value = "查询角色列表")
    @PostMapping("/checkRoles")
    public JsonResult findCheckRoles(){
        return new JsonResult(sysRoleService.findCheckRoles());
    }
    @ApiOperation(value = "更新角色信息")
    @PostMapping("/updateRole")
    public JsonResult doUpdateRole(@RequestBody SysRole sysRole){
        sysRoleService.updateRole(sysRole);
        return new JsonResult("update ok");
    }
    @ApiOperation(value = "查看单个角色")
    @PostMapping("/findById")
    public JsonResult doFindById(@RequestBody  Integer id){
        return new JsonResult(sysRoleService.findById(id));
    }
    @ApiOperation(value = "保存角色")
    @PostMapping("/save")
    public JsonResult doSaveRole(@RequestBody SysRole sysRole){
        sysRoleService.saveRole(sysRole);
        return new JsonResult("save ok");
    }
    @ApiOperation(value = "查看角色信息")
    @PostMapping("/findRoles")
    public JsonResult doFindRoles(@RequestBody  SysRole sysRole, @ModelAttribute Pager pager){
        return new JsonResult(PageUtil.startPage(pager).doSelectPageInfo(()->{
           sysRoleService.findRoles(sysRole);
        }));
        // return new JsonResult(()->sysRoleService.findRoles(sysRole));
    }
}
